/// @tags: NodeDividedTree
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

namespace BlueQuantum {

int const N = 1e5 + 5, ST = 19;

struct PriorityQueue {
  priority_queue<int> x, y;

  inline void push(int a) { x.push(a); }

  inline void del(int a) { y.push(a); }

  inline int top() {
    while (y.empty() == false && x.top() == y.top()) x.pop(), y.pop();
    return x.top();
  }

  inline int size() { return x.size() - y.size(); }

  inline void pop() {
    while (y.empty() == false && x.top() == y.top()) x.pop(), y.pop();
    x.pop();
  }

  inline int sectop() {
    int a = top();
    pop();
    int b = top();
    push(a);
    return b;
  }
} A, B[N * 2], C[N * 2];

int e_cnt, l_cnt, n, m;
int lg[N * 2], heads[N];
int status[N], siz[N], maxn[N], vis[N], vfa[N * 2];
int dep[N], st[N * 2][ST], d_cnt, dfn[N];

struct Edge {
  int v, nxt;
} e[N * 2];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

void dfs(int u, int fa) {
  dfn[u] = ++d_cnt;
  st[d_cnt][0] = dep[u];
  for (int i = heads[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v != fa) {
      dep[v] = dep[u] + 1;
      dfs(v, u);
      st[++d_cnt][0] = dep[u];
    }
  }
}

int getRT(int u, int fa, int n_cnt) {
  maxn[u] = 0, siz[u] = 1;
  int rt = 0;
  for (int i = heads[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v != fa && vis[v] == false) {
      int vrt = getRT(v, u, n_cnt);
      if (rt == 0 || maxn[vrt] < maxn[rt]) rt = vrt;
      maxn[u] = max(maxn[u], siz[v]);
      siz[u] += siz[v];
    }
  }
  maxn[u] = max(maxn[u], n_cnt - siz[u]);
  if (rt == 0 || maxn[u] < maxn[rt]) rt = u;
  return rt;
}

inline int getLcaDep(int x, int y) {
  x = dfn[x], y = dfn[y];
  if (x > y) swap(x, y);
  int k = lg[y - x + 1];
  return min(st[x][k], st[y - (1 << k) + 1][k]);
}

inline int getDis(int x, int y) { return dep[x] + dep[y] - 2 * getLcaDep(x, y); }

void calc(int u, int fa, int rt) {
  C[rt].push(getDis(u, vfa[rt]));
  siz[u] = 1;
  for (int i = heads[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa || vis[v]) continue;
    calc(v, u, rt);
    siz[u] += siz[v];
  }
}

inline void pusha(int x) {
  if (B[x].size() >= 2) A.push(B[x].top() + B[x].sectop());
}

inline void dela(int x) {
  if (B[x].size() >= 2) A.del(B[x].top() + B[x].sectop());
}

void solve(int u) {
  vis[u] = true;
  B[u].push(0);
  calc(u, 0, u);
  for (int i = heads[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (vis[v] == false) {
      int vrt = getRT(v, u, siz[v]);
      vfa[vrt] = u;
      solve(vrt);
      B[u].push(C[vrt].top());
    }
  }
  pusha(u);
}

inline void turnOn(int x) {
  dela(x);
  B[x].del(0);
  pusha(x);
  for (int i = x; vfa[i]; i = vfa[i]) {
    dela(vfa[i]);
    B[vfa[i]].del(C[i].top());
    C[i].del(getDis(x, vfa[i]));
    if (C[i].size()) B[vfa[i]].push(C[i].top());
    pusha(vfa[i]);
  }
}

inline void turnOff(int x) {
  dela(x);
  B[x].push(0);
  pusha(x);
  for (int i = x; vfa[i]; i = vfa[i]) {
    dela(vfa[i]);
    if (C[i].size()) B[vfa[i]].del(C[i].top());
    C[i].push(getDis(x, vfa[i]));
    B[vfa[i]].push(C[i].top());
    pusha(vfa[i]);
  }
}

inline void build() {
  dfs(1, 1);
  lg[0] = -1;
  for (int i = 1; i <= d_cnt; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= lg[d_cnt]; ++i)
    for (int j = 1; j + (1 << i) - 1 <= d_cnt; ++j)
      st[j][i] = min(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
  solve(getRT(1, 0, n));
}

inline int main() {
  cin >> n;
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  build();
  l_cnt = n;
  cin >> m;
  char opt;
  for (int x; m; --m) {
    cin >> opt;
    switch (opt) {
      case 'G':
        l_cnt <= 1 ? cout << l_cnt - 1 << '\n' : cout << A.top() << '\n';
        break;
      case 'C':
        cin >> x;
        status[x] == 0 ? (turnOn(x), l_cnt--) : (turnOff(x), l_cnt++);
        status[x] ^= 1;
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P2056 [ZJOI2007] 捉迷藏.in", "r", stdin);
  freopen("P2056 [ZJOI2007] 捉迷藏.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
